<?php

declare(strict_types = 1);

namespace App\Exception\Handler;

use Hyperf\Di\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Throwable;
use App\Helpers\Helper;

use Hyperf\ExceptionHandler\ExceptionHandler;
use App\Exception\AppNotFoundException;

class AppNotFoundExceptionHandler extends ExceptionHandler {



    public function handle(Throwable $throwable, ResponseInterface $response) {

        $this->stopPropagation();

        $message = $throwable->getMessage();


        return $response->withStatus(200)
            ->withAddedHeader('content-type', 'application/json')
            ->withBody(new SwooleStream(json_encode(['message'=>$message,'code'=>404])));
    }

    public function isValid(Throwable $throwable): bool {
        return $throwable instanceof AppNotFoundException;
    }
}